import Vue from 'vue'
import VueRouter from 'vue-router'
// 解决报错
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
// push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}
// replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch((err) => err)
}
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () =>
      import(/*webpackChunkName:"home"*/ '@/views/home/Home.vue'),
    redirect: '/wallet',
    children: [
      {
        path: '/wallet',
        name: 'wallet',
        meta: {
          title: '钱包',
        },
        component: () =>
          import(/*webpackChunkName:"home"*/ '@/views/home/wallet.vue'),
      },
      {
        path: '/mill',
        name: 'mill',
        meta: {
          title: '矿机',
        },
        component: () =>
          import(/*webpackChunkName:"home"*/ '@/views/home/mill.vue'),
      },
      {
        path: '/my',
        name: 'my',
        meta: {
          title: '我的',
        },
        component: () =>
          import(/*webpackChunkName:"home"*/ '@/views/home/my.vue'),
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登陆',
    },
    component: () => import(/*webpackChunkName:"mill"*/ '@/views/login/index'),
  },
  {
    path: '/register',
    name: 'register',
    meta: {
      title: '注册',
    },
    component: () => import(/*webpackChunkName:"mill"*/ '@/views/Register'),
  },
]
const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes,
})

export default router
